package com.qfedu.mapper;

import com.jayway.jsonpath.internal.function.text.Concatenate;
import com.qfedu.model.Contractor;
import com.qfedu.page.QueryPageBean;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

/**
 * 概述:
 *
 * @Author: Tbh
 * @Date: 2022/6/28 10:59
 */
public interface ContractorMapper {

    @Results(id = "conMap",value = {
            @Result(column = "cid",property = "cid"),
            @Result(column = "cname",property = "cname"),
            @Result(column = "updatetime",property = "updatetime"),
            @Result(column = "cid",property = "projects",many =
                    @Many(select = "com.qfedu.mapper.ProjectMapper.findByCid",fetchType = FetchType.EAGER)
            )
    })

    @Select("select * from contractor where cid = #{cid} and status = 1")
    Contractor findConByCid(String cid);

    @Select("select * from contractor where status = 1 limit #{currentPage},#{pageSize}")
    List<Contractor> findPage(@Param("currentPage") int currentPage, @Param("pageSize") Integer pageSize);

    @Select("select count(*) from contractor where status = 1")
    Long count();

    @Insert("insert into contractor (cid,cname,updatetime) values(#{cid},#{cname},#{updatetime})")
    int add(Contractor contractor);

    @Update("update contractor set cname=#{cname},updatetime=#{updatetime} where cid=#{cid} ")
    int updateCon(Contractor contractor);

    @Update("update contractor set status = 0 where cid = #{cid}")
    int deleteByCid(String cid);
}
